<?php
// IMAGE PROCESSING LIBRARY
class IMAGE {
    function crop($source_image,$target_image,$crop_area) {
        $source_file_name=basename($source_image);
        $source_image_type = $ext;
        switch(strtolower($source_image_type)) {
            case 'jpg':$original_image = imagecreatefromjpeg($source_image);break;
            case 'gif':$original_image = imagecreatefromgif($source_image);break;
            case 'png':$original_image = imagecreatefrompng($source_image);break;
            default:trigger_error('cropImage(): Invalid source image type', E_USER_ERROR);
            return false;
        }
        $cropped_image=imagecreatetruecolor($crop_area['width'], $crop_area['height']);
        imagecopy($cropped_image, $original_image, 0, 0, $crop_area['left'], $crop_area['top'],$crop_area['width'], $crop_area['height']);
        $target_file_name=basename($target_image);
        $target_image_type = substr($target_file_name, -3, 3);
        switch(strtolower($target_image_type)) {
            case 'jpg':imagejpeg($cropped_image, $target_image, 100);break;
            case 'gif':imagegif($cropped_image, $target_image);break;
            case 'png':imagepng($cropped_image, $target_image, 0);break;
            default:trigger_error('cropImage(): Invalid target image type', E_USER_ERROR);
            imagedestroy($cropped_image);
            imagedestroy($original_image);
            return false;
        }
        imagedestroy($cropped_image);
        imagedestroy($original_image);
    }

    function compress($source_image) {

    }

    function resize($source_image) {

    }


}
